﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Bitirme.DAL.Entities;
using Bitirme.DAL.Data_Access;


namespace Bitirme.Controllers
{
    public class ScheduleEventHandler
    {
        private List<ScheduleEventItem> ScheduleEvents;

        public ScheduleEventHandler() {

            ScheduleEvents = new List<ScheduleEventItem>();
        }

        public void AddScheduleEventItem(ScheduleEventItem scheduleEventItem) {

            ScheduleEvents.Add(scheduleEventItem);

        }

        public void GetProjectNamesByWorkPackageID() {

            foreach(ScheduleEventItem item in ScheduleEvents) {
                item.ProjectID = WorkPackageCollection.GetProjectIDByWorkPackageID(item.WorkPackageID);
                item.ProjectName = ProjectCollection.SelectProjectByID(item.ProjectID).Name;
                item.Title = item.ProjectName + "-" + item.WorkPackageName + "-" + item.EmployeeName;
            }
        }

        public String GetJSONStringofScheduleItems() {

            this.GetProjectNamesByWorkPackageID();

            System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            string stringJSON = oSerializer.Serialize(ScheduleEvents);
            return stringJSON;
        }

    }
}